/* 
 * File:   TestUnitHand.cpp
 * Author: Pouja
 *
 * Created on 15-aug-2012, 12:15:50
 */

#include <stdlib.h>
#include <iostream>
#include "../Hand.h"

/*
 * Simple C++ Test Suite
 */
 
MonsterCard *mc1 = new MonsterCard("Black Dragon", "SY-50", "Pwnage!", MonsterCard::DARK, 5, 2000, 1900, "Beasty Dragon");
MonsterCard *mc2 = new MonsterCard("White Dragon", "SY-60", "Pwnage!", MonsterCard::DARK, 5, 2000, 1900, "Beasty Dragon");    
MonsterCard *mc3 = new MonsterCard("Blue Dragon", "SY-70", "Pwnage!", MonsterCard::DARK, 5, 2000, 1900, "Beasty Dragon");  
    
void testAddCardtestSize() {
    Hand* hand=new Hand();
    hand->addCard(mc1);
    if (hand->size()!=1 /*check result*/) {
        std::cout << "%TEST_FAILED% time=0 testname=testAddCardtestSize"
                "(TestUnitHand) message=size should be 1 but it is"<< hand->size()
                << std::endl;
    }
    delete hand;
}

void testFind() {
    Hand* hand=new Hand();
    hand->addCard(mc1);
    list<Card*>::iterator result = hand->find(mc1);
    if (result==NULL){
        std::cout << "%TEST_FAILED% time=0 testname=testFind (TestUnitHand) "
                "no card found"<< std::endl;
    }
    if ((*result)->getNumber()!="SY-50") {
        std::cout << "%TEST_FAILED% time=0 testname=testFind (TestUnitHand) "
                "message=found the wrong card, it should be SY-50 but it is" 
                << (*result)->getNumber()
                << std::endl;
    }
    hand->addCard(mc2);
    result = hand->find(mc2);
    if ((*result)->getNumber()!="SY-60") {
        std::cout << "%TEST_FAILED% time=0 testname=testFind (TestUnitHand) "
                "message=found the wrong card, it should be SY-60 but it is" 
                << (*result)->getNumber()
                << std::endl;
    }
    result = hand->find(mc3);
    if (result != NULL){
        std::cout << "%TEST_FAILED% time=0 testname=testFind (TestUnitHand) "
                "message=result should be null pointer but it isn't" 
                << std::endl;
    }
    delete hand;
}

void testGetCard() {
    Hand* hand=new Hand();
    
    hand->addCard(mc1);
    hand->addCard(mc2);
    hand->addCard(mc3);
    
    Card* result = hand->getCard(0);
    
    if ((result)->getNumber()!="SY-50") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetCard (TestUnitHand) "
                "message=found the wrong card, it should be SY-50 but it is" 
                << result->getNumber()
                << std::endl;
    }
    
    result = hand->getCard(1);
    
    if ((result)->getNumber()!="SY-60") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetCard (TestUnitHand) "
                "message=found the wrong card, it should be SY-60 but it is" 
                << result->getNumber()
                << std::endl;
    }
    
    result = hand->getCard(2);
    
    if ((result)->getNumber()!="SY-70") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetCard (TestUnitHand) "
                "message=found the wrong card, it should be SY-70 but it is" 
                << result->getNumber()
                << std::endl;
    }
    delete hand;
}

void testRemoveCard() {
    Hand* hand=new Hand();
    
    hand->addCard(mc1);
    hand->addCard(mc2);
    hand->addCard(mc3);
    
    if (hand->size()!=3 /*check result*/) {
        std::cout << "%TEST_FAILED% time=0 testname=testRemoveCard (TestUnitHand)"
                " message=size should be 3 but it is"
                << hand->size()
                << std::endl;
    }
    
    hand->removeCard(mc2);
    
    Card* result = hand->getCard(0);
    
    if ((result)->getNumber()!="SY-50") {
        std::cout << "%TEST_FAILED% time=0 testname=testRemoveCard (TestUnitHand) "
                "message=found the wrong card, it should be SY-50 but it is" 
                << result->getNumber()
                << std::endl;
    }
    
    result = hand->getCard(1);
    
    if ((result)->getNumber()!="SY-70") {
        std::cout << "%TEST_FAILED% time=0 testname=testRemoveCard (TestUnitHand) "
                "message=found the wrong card, it should be SY-70 but it is" 
                << result->getNumber()
                << std::endl;
    }
    delete hand;
}

void testRemoveCard2() {
    Hand* hand=new Hand();
    
    hand->addCard(mc1);
    hand->addCard(mc2);
    hand->addCard(mc3);
    
    if (hand->size()!=3 /*check result*/) {
        std::cout << "%TEST_FAILED% time=0 testname=testRemoveCard (TestUnitHand)"
                " message=size should be 3 but it is"
                << hand->size()
                << std::endl;
    }
    
    hand->removeCard(0);
    
    Card* result = hand->getCard(0);
    
    if ((result)->getNumber()!="SY-60") {
        std::cout << "%TEST_FAILED% time=0 testname=testRemoveCard (TestUnitHand) "
                "message=found the wrong card, it should be SY-60 but it is" 
                << result->getNumber()
                << std::endl;
    }
    
    result = hand->getCard(1);
    
    if ((result)->getNumber()!="SY-70") {
        std::cout << "%TEST_FAILED% time=0 testname=testRemoveCard (TestUnitHand) "
                "message=found the wrong card, it should be SY-70 but it is" 
                << result->getNumber()
                << std::endl;
    }
    delete hand;
}

int main(int argc, char** argv) {
    std::cout << "%SUITE_STARTING% TestUnitHand" << std::endl;
    std::cout << "%SUITE_STARTED%" << std::endl;

    std::cout << "%TEST_STARTED% testAddCard (TestUnitHand)" << std::endl;
    testAddCardtestSize();
    std::cout << "%TEST_FINISHED% time=0 testAddCard (TestUnitHand)" << std::endl;

    std::cout << "%TEST_STARTED% testFind (TestUnitHand)" << std::endl;
    testFind();
    std::cout << "%TEST_FINISHED% time=0 testFind (TestUnitHand)" << std::endl;

    std::cout << "%TEST_STARTED% testGetCard (TestUnitHand)" << std::endl;
    testGetCard();
    std::cout << "%TEST_FINISHED% time=0 testGetCard (TestUnitHand)" << std::endl;

    std::cout << "%TEST_STARTED% testRemoveCard (TestUnitHand)" << std::endl;
    testRemoveCard();
    std::cout << "%TEST_FINISHED% time=0 testRemoveCard (TestUnitHand)" << std::endl;

    std::cout << "%TEST_STARTED% testRemoveCard2 (TestUnitHand)" << std::endl;
    testRemoveCard2();
    std::cout << "%TEST_FINISHED% time=0 testRemoveCard2 (TestUnitHand)" << std::endl;

    std::cout << "%SUITE_FINISHED% time=0" << std::endl;

    return (EXIT_SUCCESS);
}

